<template>
  <div>
    <zm-form :model="searchForm" ref="searchForm" inline>
      <zm-form-item>
        <zm-data-select
          v-model="searchForm.settlementType"
          k1="settlementType"
          placeholder="请选择结算方式"
          class="w150"
          clearable
        ></zm-data-select>
      </zm-form-item>
      <zm-form-item>
        <zm-data-select
          v-model="searchForm.customerType"
          :list="customerTypeList"
          placeholder="请选择客户类型"
          class="w150"
          clearable
        ></zm-data-select>
      </zm-form-item>
      <zm-form-item>
        <zm-button t="search" @click="onSearch"></zm-button>
        <zm-button type="success" @click="onEdit({})">添加</zm-button>
      </zm-form-item>
    </zm-form>

    <zm-table-data
      :data="tableParams.data"
      :columns="columns"
      :fetch="loadList"
      :table-params="tableParams"
      :show-page="false"
    >
    </zm-table-data>
    <new-deduction
      v-if="showAdd"
      v-model="showAdd"
      :obj="currentItem"
      :id="currentItem.id"
      @after-save="onSearch"
    ></new-deduction>
  </div>
</template>

<script>
import tableMixin from '@/mixins/zmTableMixin'
import { deductionColumn } from '../../const'
import overdueRuleApi from '@/api/src/overdueRule'
import NewDeduction from './components/new'
export default {
  components: { NewDeduction },
  mixins: [tableMixin],
  data () {
    return {
      columns: deductionColumn(this),
      showAdd: false,
      currentItem: {
        id: ''
      },
      searchForm: {
        settlementType: '',
        customerType: ''
      },
      customerTypeList: [
        {
          name: '个人客户',
          value: '2'
        },
        {
          name: '企业客户',
          value: '1'
        },
        {
          name: '地产客户',
          value: '3'
        }
      ]
    }
  },
  computed: {},
  watch: {},
  created () {},
  methods: {
    async loadList () {
      let res = await overdueRuleApi.getList(this.searchForm)
      console.log(res)
      this.initialTableData(res.list, res.count)
    },
    onEdit (row) {
      this.showAdd = true
      this.currentItem = row
    },
    onDelete (row) {
      this.$msg.confirmDelete().then(async () => {
        await overdueRuleApi.delete({ id: row.id })
        this.onSearch()
        this.$msg.success()
      })
    }
  }
}
</script>
